package com.caiheng.api.service.wxuser.impl;

import cn.hutool.core.collection.CollUtil;
import com.caiheng.api.dao.wxuser.UserMerCouponMapper;
import com.caiheng.api.entity.wxuser.UserMerCoupon;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import com.caiheng.api.service.wxuser.UserMerCouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户的商家抵扣券Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-24
 */
@Service
public class UserMerCouponServiceImpl extends BaseServiceImpl<UserMerCouponMapper, UserMerCoupon> implements UserMerCouponService {

    @Resource
    private UserMerCouponMapper userMerCouponMapper;

    @Override
    public List<UserMerCoupon> getMyAllEnableCoupon(int userId, int mer_id) {

        List<UserMerCoupon> listAll = new ArrayList<>();

        Map<String,Object> mapCoupon = new HashMap<>();
        mapCoupon.put("mer_id",mer_id);
        mapCoupon.put("is_all",1);
        List<UserMerCoupon> coupons = userMerCouponMapper.selectMyCouponByProductId(mapCoupon);
        if(CollUtil.isNotEmpty(coupons)){
            listAll.addAll(coupons);
        }

        // 所有需要指定商品的抵扣券
        Map<String,Object> mapCouponProduct = new HashMap<>();
        mapCouponProduct.put("mer_id",mer_id);
        mapCouponProduct.put("is_all",0);
        mapCouponProduct.put("coupon_type",0);
        List<UserMerCoupon> couponProducts = userMerCouponMapper.selectMyCouponByProductId(mapCouponProduct);
        listAll.addAll(couponProducts);
        return listAll;
    }

    @Override
    public List<UserMerCoupon> selectMyCouponByProductId(Map<String, Object> map) {
        return userMerCouponMapper.selectMyCouponByProductId(map);
    }
}
